<extend name="Public:base" />
<block name="content">
    <script>
        function preview(event) {
            var files = event.target.files;
            var reader  = new FileReader();
            reader.onload = function (event) {
                var result = event.target.result;
                var x = document.getElementById("icon");
                if (!x || !x.value) return;
                var patn = /\.jpg$|\.jpeg$|\.gif$|\.png$/i;
                if (patn.test(x.value)) {
                    var y = document.getElementById("img");
                    var i = document.getElementById("ic");
                    if (y) {
                        y.src = result;
                        i.value = result;
                    } else {
                        var img = document.createElement("img");
                        img.setAttribute("src", result);
                        img.setAttribute("width", "145");
                        img.setAttribute("height", "155");
                        img.setAttribute("id", "img");
                        document.getElementById("up").appendChild(img);
                    }
                } else {
                    alert("您选择的似乎不是图像文件");
                }
                reader = null;
            }
            reader.readAsDataURL(files[0]);

        }

        function check(){
            var title = $('input[name=title]').val();
            var desc = $('textarea[name=desc]').val();
            var img = document.getElementById("icon").value;

            if($.trim(title) == ""){
                alert('标题不能为空');
                return false;
            }
            if($.trim(desc)==''){
                alert('内容不能为空');
                return false;
            }


        }

    </script>
    <div class="page-header">
        <div class="row">
            <div class="col-xs-12">

                <form class="form-horizontal"  id="validation-form" method="post" enctype="multipart/form-data" onsubmit="return check()" action='{:U("Banner/edit")}'>
                    <div class="form-group required">
                        <label class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-10">
                            <input value="{$detail['title']}" class="form-control" style="width:220px;" type="text" placeholder="" name="title"  />
                        </div>
                    </div>
                    <input type="hidden" name="id" value="{$detail['id']}">
                    <div class="form-group required">
                        <label class="col-sm-2 control-label">内容</label>
                        <div class="col-sm-10">
                            <textarea  value="" name="desc" style="margin: 0px; width: 488px; height: 328px;">{$detail['desc']?$detail['desc']:''}</textarea>
                        </div>
                    </div>
                    <div class="form-group required">
                        <label class="col-sm-2 control-label">分类</label>
                        <div class="col-sm-10">
                            <select name="type">
                                <option value="1" {$detail['type']==1?'selected':''}>用户首页banner</option>
                                <option value="2" {$detail['type']==2?'selected':''}>师傅首页banner</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group required">
                        <label class="col-sm-2 control-label">状态</label>
                        <label><input type="radio"  name="status" value="1" {$detail['status']==1?"checked='checked'":''}/>启用</label>
                        <label><input type="radio"  name="status" value="2" {$detail['status']==2?"checked='checked'":''}/>停用</label>
                    </div>

                    <div class="form-group required">
                        <label class="col-sm-2 control-label">封面</label>
                        <div class="col-sm-10" id="up">
                            <input type="file" name="icon" id="icon" onchange="preview(event)">
                            <img src="{$detail['pic']}" width="145" height="155" id="img">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-left" style="visibility: hidden;">保存：</label>
                        <div class="col-sm-10">
                            <input  type="submit" value="保存" class="btn btn-primary btn-sm radius5" />
                        </div>
                    </div>
                </form>

            </div>

</block>

